#!/usr/bin/python3
import json
from typing import List

def getPkgVersion(jsonData) -> str:
    dependencies=""
    for package, version in jsonData.items():
        if version.startswith("^"):
            version = version[1:]
        print(f"Package: {package}, Version: {version}")
        dependencies+= f'"{package}": '

        ps=package.replace("/", "\\")
        with open(f"C:\\work\\prod\\cmdb2\\neatlogic-itom-all\\neatlogic-web\\node_modules-0\\{ps}\\package.json", "r", encoding='utf-8') as pkgVerFile:
             pJson=json.load(pkgVerFile)
             useVersion=pJson.get('version')
             print(f" Show Use Version: {useVersion}")
        
        dependencies+=f'"{useVersion}",\n'

    print(dependencies)
    return dependencies

if __name__ == "__main__":
    with open("C:\\temp\\cmdbweb\\package.json", "r", encoding='utf-8') as file:
        data = json.load(file)
    
    deps=getPkgVersion(data.get('dependencies'))
    devDependencies=getPkgVersion(data.get('devDependencies'))

    print("如下的版本信息拷贝到：package.json 的 dependencies 和 devDependencies 节点中")
    print(f"dependencies: \n{deps}")
    print(f"devDependencies: \n{devDependencies}")